let express = require('express');   //引入express
let Mock = require('mockjs');       //引入mock

let app = express();        //实例化express

app.all('*', function(req, res, next) { // 解决跨域问题
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    next();
});

let articleAPI = require('./article')
let newsDataAPI = require('./newsData')
let photoDataAPI = require('./photoData')
let goodsDataAPI = require('./goodsData')
// ==================home->新闻接口============

app.get('/lunbotu', function (req, res) {
  res.json(Mock.mock(newsDataAPI.getLunbotu(req)))
})

  app.get('/news/list', function (req, res) {
    res.json(Mock.mock(newsDataAPI.getList(req)))
  })

  app.get('/news/detail', function (req, res) {
    res.json(Mock.mock(newsDataAPI.getDetail(req)))
  })

  app.get('/comments', function (req, res) {
    res.json(Mock.mock(newsDataAPI.getComments(req)))
  })

  app.post('/postComment', function (req, res) {
    res.json(Mock.mock(newsDataAPI.postComment(req)))
  })
// ==================home->图片接口============
app.get('/photo/imgCate', function (req, res) {
  res.json(Mock.mock(photoDataAPI.getImgCate(req)))
})
//=================goods->接口===================
app.get('/goods/goodsList',function(req,res) {
    res.json(Mock.mock(goodsDataAPI.getGoodsList(req)))
})
app.get('/goods/goodsDetail',function(req,res) {
    res.json(Mock.mock(goodsDataAPI.getGoodsDetail(req)))
})

app.get('/car/carList',function(req,res) {
    res.json(Mock.mock(goodsDataAPI.getCarList(req)))
})


app.listen('8090', () => {
    console.log('监听端口 8090')
})

app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
});
